/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Iskandar Sarkawi
 */
public class ArrayExample {

    public static void main(String[] args) {
        example1();
        example2();//using x and y: a bit confusing
        example3();//using row and column: better use row and column
    }
    public static void example1(){

        int matrix[][] = {{0,1,2,3},{1,0,3,2},{2,3,0,1}};

        System.out.println("Example 1");
        for(int y=0; y<3; y++){
            for(int x=0; x<4; x++){
                System.out.print(" "+ matrix[y][x]);                
            }
            System.out.println();
        }
        /*
        output:
        0 1 2 3
        1 0 3 2
        2 3 0 1
        */
    }
    
    public static void example2(){
        int y=3, x=4;
        int[][] matrix = new int[y][x];

        //int matrix[][] = {{0,1,2,3},{1,0,3,2},{2,3,0,1}};
        
        matrix[0][0] = 0;
        matrix[0][1] = 1;
        matrix[0][2] = 2;
        matrix[0][3] = 3;

        matrix[1][0] = 1;
        matrix[1][1] = 0;
        matrix[1][2] = 3;
        matrix[1][3] = 2;

        matrix[2][0] = 2;
        matrix[2][1] = 3;
        matrix[2][2] = 0;
        matrix[2][3] = 1;       

        System.out.println("\nExample2");
        for(y=0; y<3; y++){
            for(x=0; x<4; x++){
                System.out.print(" "+ matrix[y][x]);
            }
            System.out.println();
        }
        /*
        output:
        0 1 2 3
        1 0 3 2
        2 3 0 1
        */
    }

    public static void example3(){
        int r=3, c=4; //r for row; c for column
        int[][] matrix = new int[r][c];

        //int matrix[][] = {{0,1,2,3},{1,0,3,2},{2,3,0,1}};

        matrix[0][0] = 0;
        matrix[0][1] = 1;
        matrix[0][2] = 2;
        matrix[0][3] = 3;

        matrix[1][0] = 1;
        matrix[1][1] = 0;
        matrix[1][2] = 3;
        matrix[1][3] = 2;

        matrix[2][0] = 2;
        matrix[2][1] = 3;
        matrix[2][2] = 0;
        matrix[2][3] = 1;

        System.out.println("\nExample3");
        for(r=0; r<3; r++){
            for(c=0; c<4; c++){
                System.out.print(" "+ matrix[r][c]);
            }
            System.out.println();
        }
        /*
        output:
        0 1 2 3
        1 0 3 2
        2 3 0 1
        */
    }

}
